#include<iostream>
using namespace std;
const int N = 210;
int mp[N][N];
int dis[N];
bool st[N];
int n, m;
void dijkstra(int x)
{
	dis[x] = 0;
	for (int i = 0; i < n; i++) {
		int t = -1;
		for (int j = 1; j <= n; j++) {
			if (!st[j] && (t == -1 || dis[j] > dis[t])) {
				t = j;
			}
		}
		st[t] = 1;
		for (int j = 1; j <= n; j++) {
			dis[j] = min(dis[j], dis[t] + mp[t][j]);
		}
	}
}
int main()
{
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		memset(mp, 0x3f, sizeof(mp));
		memset(dis, 0x3f, sizeof(dis));
		memset(st, 0, sizeof(st));
		while (m--) {
			int a, b, c;
			cin >> a >> b >> c;
			mp[a][b] = mp[b][a] = min(mp[a][b], c);
		}
		dijkstra(1);
		cout << dis[n] << endl;
	}
	return 0;
}